package cn.hls.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.hls.dao.ModuleDao;
import cn.hls.entity.Module;
import cn.hls.entity.vo.ExtTree;
import cn.hls.entity.vo.PageInfo;
import cn.hls.service.ModuleService;

@Service("moduleService")
public class ModuleServiceBean extends BaseServiceBean<Module> implements ModuleService {
	@Resource(name = "moduleDaoImpl")
	private ModuleDao moduleDao;
	
	
	@Override
	public boolean add(Module entity) throws Exception {
		if (entity.getParent() != null) {
			// 设置上级的模块对象
			entity.setParent(moduleDao.find(entity.getParent().getId()));
		}
		return super.add(entity);
	}
	@Override
	public boolean update(Module entity) throws Exception {
		Module tempEntity=moduleDao.find(entity.getId());
		tempEntity.setName(entity.getName().trim());
		tempEntity.setCode(entity.getCode().trim());
		tempEntity.setExpend(entity.getExpend());
		tempEntity.setRemark(entity.getRemark()==null?null:entity.getRemark().trim());
		tempEntity.setUrl(entity.getUrl()==null?null:entity.getUrl().trim());
		tempEntity.setUpdateTime(new Date());
		return super.update(tempEntity);
	}
	
	@Override
	public List<ExtTree> loadChildModules(Module module, Long nodeId) throws Exception {
		return moduleDao.loadChildModules(module, nodeId);
	}

	@Override
	public PageInfo<Module> loadModules(Module module, PageInfo<Module> page) throws Exception {
		return moduleDao.loadModules(module, page);
	}

	@Override
	public void updateModuleSort(String ids) throws Exception {
		moduleDao.updateModuleSort(ids);
	}

	@Override
	public Module findModule(String paramString) throws Exception {
		return moduleDao.findModule(paramString);
	}

	@Override
	public Module findModule(Module entity) throws Exception {
		return moduleDao.findModule(entity);
	}

	@Override
	public String deleteModule(Long id) throws Exception {
		return moduleDao.deleteModule(id);
	}

}
